#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct student
{
	char name[20];
	int age;
	double weight;
};

int main()
{
	//**********************************静态内存分配****************************************
	struct student A1[3]={{"张震",20,70.5},{"王荣兴",19,60.5},{"蒋浩",21,5.5}};
	for(int i=0;i<3;i++)//整体循环输出
	{
		printf("姓名：%s\t年龄：%d\t体重：%.2lf\n",A1[i].name,A1[i].age,A1[i].weight);
	}
	//部分初始化
	struct student A2[3]={{"li",20,20.5},{"zhang三",21,19.2}};
	struct student A3 =
	{
		.age =20,
		.weight =60.5
	};


	//**********************************动态分配内存****************************************
	struct student *p = malloc(sizeof(struct student));
	strcpy(p->name,"章三");
	p->age = 20;
	p->weight = 19.6;

	printf("姓名：%s\t年龄：%d\t体重：%.2lf\n",p->name,p->age,p->weight);

	//如果指针指向一个连续的内存空间，指针可以直接当作数组名来使用
	struct student *m =malloc(sizeof(struct student)*3);//动态内存分配

	strcpy(m[0].name,0"细狗");
	m[0].age=20;
	m[0].weight=60.8;

	m++;

	return 0;
}
